/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hexagon;

/**
 *
 * @author Colin Bundervoet
 */
public class HorizontalHexagons extends HexagonField
{
    public HorizontalHexagons(boolean firstColumnShorter, int xSize, int ySize)
    {
        super(firstColumnShorter, xSize, ySize);
    }

    @Override
    public boolean canMoveNorth()
    {
        return yPos > 0 && getTile(xPos, yPos - 1).isAvailable();
    }

    @Override
    public void moveNorth()
    {
    }

    @Override
    public void moveSouth()
    {
    }

    //TODO add availabilitycheck from isAvailable(x, y)
    
    @Override
    public void moveNorthEast()
    {
        if (xPos < field.length) {
            if (xPos % 2 == 0 ^ firstSeriesIsShorter) {
                if(isAvailable(xPos + 1, yPos))
                    xPos++;
                else
                    throw new ImpossibleMoveException();
            }
            else {
                if (yPos > 0 && isAvailable(xPos + 1, yPos - 1)) {
                    xPos++;
                    yPos--;
                }
                else {
                    throw new ImpossibleMoveException();
                }
            }
        }
        else {
            throw new ImpossibleMoveException();
        }
    }

    @Override
    public void moveNorthWest()
    {
        if (xPos > 0) {
            if (xPos % 2 == 0 ^ firstSeriesIsShorter) {
                if (isAvailable(xPos - 1, yPos))
                    xPos--;
                else
                    throw new ImpossibleMoveException();
            }
            else {
                if (yPos > 0 && isAvailable(xPos - 1, yPos - 1)) {
                    xPos--;
                    yPos--;
                }
                else {
                    throw new ImpossibleMoveException();
                }
            }
        }
        else {
            throw new ImpossibleMoveException();
        }
    }

    @Override
    public void moveSouthEast()
    {
        if (xPos < field.length) {
            if (xPos % 2 == 0 ^ !firstSeriesIsShorter) {
                xPos++;
            }
            else {
                if (yPos < field[xPos].length) {
                    xPos++;
                    yPos++;
                }
                else {
                    throw new ImpossibleMoveException();
                }
            }
        }
        else {
            throw new ImpossibleMoveException();
        }
    }

    @Override
    public void moveSouthWest()
    {
        if (xPos > 0) {
            if (xPos % 2 == 0 ^ !firstSeriesIsShorter) {
                xPos--;
            }
            else {
                if (yPos < field[xPos].length) {
                    xPos--;
                    yPos++;
                }
                else {
                    throw new ImpossibleMoveException();
                }
            }
        }
        else {
            throw new ImpossibleMoveException();
        }
    }
}
